package com.wantong.jianpu.activitys;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

import com.lxj.xpopup.XPopup;
import com.wantong.jianpu.BR;
import com.wantong.jianpu.R;
import com.wantong.jianpu.base.BaseXActivity;
import com.wantong.jianpu.customviews.SelectImageView;
import com.wantong.jianpu.databinding.ActivityCreateTourBinding;
import com.wantong.jianpu.viewmodels.CreateTourViewModel;

import java.util.List;

public class CreateTourActivity extends BaseXActivity<ActivityCreateTourBinding, CreateTourViewModel> {

    @Override
    public int initContentView(Bundle savedInstanceState) {
        return R.layout.activity_create_tour;
    }

    @Override
    public int initVariableId() {
        return BR.viewModel;
    }

    @Override
    public void initData() {
        super.initData();
        setToolbar(binding.baseToolBar);
        viewModel.id=getIntent().getExtras().getString("id");
        viewModel.currentNum=getIntent().getExtras().getInt("currentNum");
        binding.selectImageView.setActivity(this);
        viewModel.image.observe(this, selectImageBeans -> {
            binding.selectImageView.setData(selectImageBeans);
        });
        binding.selectImageView.setCallBack(new SelectImageView.SelectCallBack() {
            @Override
            public void selectImagePath(List<String> filePath) {
                viewModel.upLoadFile(filePath);
            }

            @Override
            public void deletePosition(int position) {
                viewModel.commitData.getValue().getImageList().remove(position);
            }
        });

        viewModel.locationDialogEvent.observe(this, strings -> {
            new XPopup.Builder(CreateTourActivity.this)
                    .asBottomList("请选择巡查位置", strings,
                            (position, text) -> {
                                viewModel.setLocationPosition(position);
                            }).show();
        });

        viewModel.gradeDialogEvent.observe(this, strings -> {
            new XPopup.Builder(CreateTourActivity.this)
                    .asBottomList("请选择维修等级", strings,
                            (position, text) -> {
                                viewModel.setGrade(text);
                            }).show();
        });

        viewModel.rangeDialogEvent.observe(this, strings -> {
            new XPopup.Builder(CreateTourActivity.this)
                    .asBottomList("请选择保养范围", strings,
                            (position, text) -> {
                                viewModel.setRangePosition(position);
                            }).show();
        });
    }
}